/**
 * @author:linjiye
 * @date: 2025/2/26
 * @desc:
 **/

import {StyleSheet, Text, View} from 'react-native'
import React, {useEffect, useState} from 'react'

type Props = {}

const StreamWriterText = ({chunks}: Props) => {
  const [displayText, setDisplayText] = useState('');
  const [currentIndex, setCurrentIndex] = useState(0);

  useEffect(() => {
    const interval = setInterval(() => {
      if (currentIndex < chunks.length) {
        setDisplayText((prevText) => prevText + chunks[currentIndex]);
        setCurrentIndex((prevIndex) => prevIndex + 1);
      } else {
        clearInterval(interval);
      }
    }, 100); // 每 100 毫秒显示一个新的数据块，可根据需要调整

    return () => clearInterval(interval);
  }, [chunks, currentIndex]);

  return <Text>{displayText}</Text>;
}

export default StreamWriterText

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
    },
})